<template>
  <div class="base-echart">
    <div ref="echartDivRef" :style="{ widh: width, height: height }"></div>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, ref, watchEffect } from 'vue'
import { EChartsOption } from 'echarts'
import BaseEchar from '@/base-ui/echart'

import useEchart from './hooks/useEchart'
//定义props
const props = withDefaults(
  defineProps<{
    options: EChartsOption
    width?: string
    height?: string
  }>(),
  {
    width: '100%',
    height: '360px',
  }
)

const echartDivRef = ref<HTMLElement>()

onMounted(() => {
  const { setOptions } = useEchart(echartDivRef.value!)

  watchEffect(() => {
    setOptions(props.options)
  })
})
</script>

<style scoped></style>
